/*
 * Copyright (C) 2020 The LINN Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.juqimiao.linn.command;

import com.juqimiao.linn.interception.InterceptorI;
import com.juqimiao.linn.interception.PostInterceptor;
import com.juqimiao.linn.interception.PreInterceptor;
import com.juqimiao.linn.transfer.Command;
import com.juqimiao.linn.transfer.Response;

/**
 * 用于拦截CommandExecutor执行过程的拦截器的标识接口。
 *
 * 此拦截器只用于拦截 CommandExecutorI.execute方法。
 * 它配合{@link PreInterceptor} 和 {@link PostInterceptor}共同使用。
 * 其中：
 *
 * 当{@link PreInterceptor}被用于标识实现类的时候，CommandInterceptorI.preIntercept才需要具体实现。
 *
 * 当{@link PostInterceptor}被用于标识实现类的时候，CommandInterceptorI.postIntercept才需要具体实现。
 *
 * @param <R> 一个响应对象。Response object.
 * @param <C> 一个命令对象。Command object.
 *
 * @author  Collin Cai
 */
public interface CommandInterceptorI<R extends Response, C extends Command> extends InterceptorI {
    /**
     * 拦截目标执行前执行的拦截方法。
     *
     * @param command 一个命令对象。BaseCommand object.
     */
    default void preIntercept(C command) {
    }

    /**
     * 拦截目标执行前执行的拦截方法。
     *
     * @param response 一个响应对象。Response object.
     * @param command  一个命令对象。Command object.
     */
    default void postIntercept(R response, C command) {
    }
}
